<template>
  <!-- 隐患处理 待验收-->
  <view class="pwd-retrieve-container">
    <hidden-danger-info :detail="detail" />
    <review-info :detail="detail" />
    <rectify-info :detail="detail" />
    <uni-forms ref="form" :value="acceptInfo" labelWidth="60vw" labelPosition="top">
      <view class="hidden-title">验收信息</view>
      <view class="background-white">
        <uni-forms-item name="acceptanceIdea" class="acceptance" required>
          <view slot="label">
            <view class="flex align-center">
              <view class="mr-20">验收意见</view>
              <view class="acceptance-list">
                <view
                  class="acceptance-item"
                  v-for="(item, index) in acceptanceList"
                  :key="item.code"
                  :class="{
                    active: acceptInfo.acceptanceIdea == item.dictValue
                  }"
                  @click="acceptInfo.acceptanceIdea = item.dictValue"
                >
                  <image
                    class="icon-style"
                    v-show="acceptInfo.acceptanceIdea != item.dictValue"
                    src="/static/images/work/dbd//selected_no.png"
                    mode="aspectFill"
                  ></image>
                  <image
                    class="icon-style"
                    v-show="acceptInfo.acceptanceIdea == item.dictValue"
                    src="/static/images/work/dbd//selected_yes.png"
                    mode="aspectFill"
                  ></image>
                  <text class="content">{{ item.dictLabel }}</text>
                </view>
              </view>
            </view>
          </view>
        </uni-forms-item>
      </view>
      <view class="background-white">
        <uni-forms-item name="acceptanceResult" label="验收结果">
          <textarea
            v-model="acceptInfo.acceptanceResult"
            class="text-area"
            placeholder-class="placeholder__style"
            placeholder="请根据实际情况简要说明验收结果(限50字)"
            maxlength="50"
          />
        </uni-forms-item>
      </view>
      <view class="background-white bor-top">
        <uni-forms-item name="acceptanceRemark" label="备注">
          <textarea
            v-model="acceptInfo.acceptanceRemark"
            class="text-area"
            placeholder-class="placeholder__style"
            placeholder="请根据实际情况简要说明(限50字)"
            maxlength="50"
          />
        </uni-forms-item>
      </view>

      <view class="background-white bor-top bottom">
        <uni-forms-item name="acceptancePhotoUrl" label="上传照片（最多3张）" labelWidth="150">
          <image-upload state="edit" :imageUrl="acceptInfo.acceptancePhotoUrl" @change="imageOnChange"></image-upload>
        </uni-forms-item>
      </view>
    </uni-forms>

    <view class="submit-group">
      <button @click="submit" class="u-button" :ripple="true">保存</button>
    </view>
  </view>
</template>

<script>
import ImageUpload from '@/components/image-upload/index.vue'

import HiddenDangerInfo from './components/HiddenDangerInfo'
import ReviewInfo from './components/ReviewInfo'
import RectifyInfo from './components/RectifyInfo'
import { hiddenDangerAccept } from '@/api/dbd/hiddenDangerDeal'
import { getHiddenDangerDetail } from '@/api/dbd/hiddenDangerBook'
import { getDicts } from '@/api/system/dict.js'

export default {
  components: {
    RectifyInfo,
    ReviewInfo,
    HiddenDangerInfo,
    ImageUpload
  },
  data() {
    return {
      area: '',
      detail: {},
      acceptInfo: {
        acceptanceRemark: '',
        acceptanceResult: '',
        acceptancePhotoUrl: '',
        acceptanceIdea: '0'
      },
      rules: {
        acceptanceIdea: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        },
        acceptanceResult: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        }
      },
      acceptanceList: []
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  onLoad({ managerId }) {
    this.getDetail(managerId)
    this.getDicts()
  },
  methods: {
    getDicts() {
      getDicts('dbd_manager_acceptance_idea').then((res) => {
        this.acceptanceList = res.data
      })
    },
    imageOnChange(urlList) {
      this.acceptInfo.acceptancePhotoUrl = urlList.join(',')
    },
    getDetail(managerId) {
      getHiddenDangerDetail(managerId).then((res) => {
        this.detail = res.data
      })
    },
    submit() {
      const eventChannel = this.getOpenerEventChannel()
      this.$refs.form.validate().then((res) => {
        hiddenDangerAccept({
          ...this.acceptInfo,
          managerId: this.detail.managerId
        }).then(() => {
          this.$modal.msgSuccess('验收成功')
          eventChannel.emit('reloadEvent', true)
          uni.navigateBack({
            delta: 1
          })
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.pwd-retrieve-container {
  padding-bottom: 200rpx;
  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx 1rpx 30rpx;

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}

.acceptance {
  margin-bottom: 10rpx;
}
.acceptance-list {
  display: flex;

  .acceptance-item {
    display: flex;
    align-items: center;
    margin-left: 20rpx;
    color: #333;

    .icon-style {
      width: 36rpx;
      height: 36rpx;
      margin-right: 10rpx;
    }

    .content {
      flex: 1;
    }
  }
}
</style>
